﻿#include "ManageMent_gui.h"
#include "widgets/Window.h"
#include "widgets/Table.h"
#include "widgets/Timer.h"
#include <iostream>
#include <unordered_map>

// 存储用户名和密码的哈希表
std::unordered_map<std::string, std::string> userDatabase;

// 注册函数
void registerUser(const std::string& username, const std::string& password) 
{
    auto it = userDatabase.find(username);
    if (it != userDatabase.end()) 
    {
        std::cout << "用户名已存在，请选择其他用户名。" << std::endl;
    }
    else {
        userDatabase[username] = password;
        std::cout << "注册成功！" << std::endl;
    }
}

// 登录函数
bool loginUser(const std::string& username, const std::string& password) 
{
    auto it = userDatabase.find(username);
    if (it != userDatabase.end() && it->second == password) 
    {
        std::cout << "登录成功！" << std::endl;

        //界面实现:
        {
            //显示控制台窗口 //禁用绘图窗口的关闭按钮
            Window w(960, 640, EX_SHOWCONSOLE | EX_NOCLOSE);
            w.setWindowTitle("学生信息管理系统");
            ManageMent m;
            m.run();


            return w.exec();
        }

        return true;
    }
    else 
    {
        std::cout << "用户名或密码错误。" << std::endl;
        return false;
    }
}
void setConsoleBackgroundColor(WORD color)
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, color);
}

int main()
{  
    //颜色
    setConsoleBackgroundColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    
    int choice;
    std::string username, password;

    while (true) 
    {
        std::cout << "0. 注册" << std::endl;
        std::cout << "1. 登录" << std::endl;
        std::cout << "2. 退出" << std::endl;
        std::cout << "请输入你的选择: ";
        std::cin >> choice;
        switch (choice)
        {
        case 0:
            std::cout << "请输入用户名: ";
            std::cin >> username;
            std::cout << "请输入密码: ";
            std::cin >> password;
            registerUser(username, password);
            break;

        case 1:
            std::cout << "请输入用户名: ";
            std::cin >> username;
            std::cout << "请输入密码: ";
            std::cin >> password;
            loginUser(username, password);
            break;

        case 2:
            std::cout << std::endl << "已退出系统" << std::endl;
            return 0;
            break;

        default:
            std::cout << "无效的选择，请重新输入。" << std::endl;
            break;
        }
    }
    return 0;
}